/******************************************************************
 * This program was written as part of
 *   Assignment 4
 *   Computer Graphics                                             
 *   Semester 1, 2013
 *   School of Computer Science,
 *   The University of Adelaide
 *                                                                          
 * I declare that all material in this assessment is my own work except where
 * there is clear acknowledgement and reference to the work of others. I have
 * read the University Policy Statement on Plagiarism, Collusion and Related
 * Forms of Cheating:  

 * http://www.adelaide.edu.au/policies/?230

 * I give permission for my assessment work, including my subversion
 * repository, to be reproduced and submitted to academic staff for the
 * purposes of assessment and to be copied, submitted and retained in a form
 * suitable for electronic checking of plagiarism.  
                            
 * Authors:
 *  Terry Moschou    a1208955
 *  Salih Al-Rashid  a1210108
 *  Ben McAleer      a1212203
*******************************************************************/

#include "Scene.hpp"
#include "Skybox.hpp"
#include "Model.hpp"
#include "Context.hpp"
#include "Water.hpp"

Scene::Scene()
  : Object(0, mat4(1.0f), 0, "Scene")
{ 

  
  

  
//   Model * waterModel = new Model("resources/models/water.obj");
//   new Object(this, mat4(1.0f), waterModel, "water");
 
  m_segway = new Segway(this);

  m_player = new Player(this);
  
  mat4 skyBoxModelMatrix = glm::scale(mat4(1.0f), vec3(500.0f, 500.0f, 500.0f));
  m_skybox = new SkyBox(this, skyBoxModelMatrix);
  
  Model * terryModel = new Model("resources/models/terraingrass.obj");
  m_terrain = new Terrain(this, terryModel, 64, 64);
  
  
  
  Model * bigwalls = new Model("resources/models/boundarywalls.obj");
  new Object(m_terrain,mat4(1.0f),bigwalls,"Terrain Boundary");
  
  Model * torc = new Model("resources/models/torch.obj");
  mat4 tmatrix = glm::rotate(mat4(1.0f),80.0f,vec3(1.0f,0.0f,0.0f));
  Equipment * torch = new Equipment(this, torc, tmatrix, TORCH);
  
  
  Model * swor = new Model("resources/models/sword.obj");
  mat4 smatrix = glm::translate(mat4(1.0f),vec3(0.0f,0.8f,0.0f));
  smatrix = glm::rotate(smatrix,180.0f,vec3(1.0f,0.0f,0.0f));
  Equipment * sword = new Equipment(this, swor, smatrix, SWORD);
  
  Model * tree = new Model("resources/models/tree.obj");
  tree->m_bounds.dis.x *= 0.5f;
  tree->m_bounds.dis.z *= 0.5f; //Nobody got time for dat
  tree->m_bounds.dis.y *= 5.0f;
  
  mat4 treemat;
  vec2 treepos;
  for(int i = 0; i<14; ++i) {
    switch(i) {
      case 0: treepos = vec2(100,5); break;
      case 1: treepos = vec2(70,45); break;
      case 2: treepos = vec2(95,15); break;
      case 3: treepos = vec2(60,10); break;
      case 4: treepos = vec2(100,56); break;
      case 5: treepos = vec2(95,50); break;
      case 6: treepos = vec2(8,32); break;
      case 7: treepos = vec2(54,82); break;
      case 8: treepos = vec2(58,84); break;
      case 9: treepos = vec2(52,86); break;
      case 10: treepos = vec2(112,100); break;
      case 11: treepos = vec2(116,104); break;
      case 12: treepos = vec2(122,104); break;
      case 13: treepos = vec2(126,106); break;
    }
    treemat = glm:: translate(mat4(1.0f),vec3(treepos.x,m_terrain->getHeight(treepos.x,treepos.y),treepos.y));
    new Object(this,treemat,tree,"Tree");
  }
  
  Model * stump = new Model("resources/models/stump.obj");
  stump->m_bounds.dis.x *= 0.6f;
  stump->m_bounds.dis.z *= 0.6f;
  stump->m_bounds.pos.x += 0.1f;
  stump->m_bounds.pos.z += 0.1f;
  
  for(int i = 0; i<5; ++i) {
    switch(i) {
      case 0: treepos = vec2(96,6); break;
      case 1: treepos = vec2(30,42); break;
      case 2: treepos = vec2(7,16); break;
      case 3: treepos = vec2(50,90); break;
      case 4: treepos = vec2(125,100); break;
    }
    treemat = glm:: translate(mat4(1.0f),vec3(treepos.x,m_terrain->getHeight(treepos.x,treepos.y),treepos.y));
    new Object(this,treemat,stump,"Tree Stump");
  }
  
  Model * barrel = new Model("resources/models/barrel.obj");
  
  for(int i = 0; i<7; ++i) {
    switch(i) {
      case 0: treepos = vec2(122,44); break;
      case 1: treepos = vec2(110,34); break;
      case 2: treepos = vec2(120,16); break;
      case 3: treepos = vec2(120,14); break;
      case 4: treepos = vec2(124,14); break;
      case 5: treepos = vec2(80,80); break;
      case 6: treepos = vec2(30,6); break;
    }
    treemat = glm:: translate(mat4(1.0f),vec3(treepos.x,m_terrain->getHeight(treepos.x,treepos.y),treepos.y));
    new Object(this,treemat,barrel,"Barrel 'o Beer");
  }
  
  Model * c1 = new Model("resources/models/cavefront1.obj");
  Model * c2 = new Model("resources/models/cavefront2.obj");
  Model * c3 = new Model("resources/models/caveside.obj");
  Model * c4 = new Model("resources/models/caveotherside.obj");
  Model * c5 = new Model("resources/models/cavetop.obj");
  Model * c6 = new Model("resources/models/caveback.obj");
  new Object(this,mat4(1.0f),c1,"Cave1");
  new Object(this,glm::translate(mat4(1.0f),vec3(-7.0f,0.0f,0.0f)),c2,"Cave2 Secret Door");
  new Object(this,mat4(1.0f),c3,"Cave3");
  new Object(this,mat4(1.0f),c4,"Cave4");
  new Object(this,mat4(1.0f),c5,"Cave5");
  new Object(this,mat4(1.0f),c6,"Cave6");

  Model * cane = new Model("resources/models/walkingstick.obj");
  Equipment * walkingstick = new Equipment(this,cane,glm::translate(mat4(1.0f),vec3(0.0f,2.0f,0.0f)),0);

  Model * opengl = new Model("resources/models/opengl.obj");
  Equipment * textbook = new Equipment(this,opengl,mat4(1.0f),0);
  
  Model * c7 = new Model("resources/models/camp.obj");
  c7->m_bounds.dis.y *= 5.0f;
  new Object(this,mat4(1.0f),c7,"Campfire");
  

  

  
  
  Model * bl = new Model("resources/models/block.obj");
  vec3 blv = vec3(37,0,5);
  new Object(this,glm::translate(mat4(1.0f),blv),bl,"Moon");
  blv += vec3(2,0,0);
  new Object(this,glm::translate(mat4(1.0f),blv),bl,"Moon");
  blv += vec3(0,2,0);
  new Object(this,glm::translate(mat4(1.0f),blv),bl,"Moon");
  blv += vec3(2,0,0);
  new Object(this,glm::translate(mat4(1.0f),blv),bl,"Moon");
  blv += vec3(0,0,2);
  new Object(this,glm::translate(mat4(1.0f),blv),bl,"Moon");
  blv += vec3(0,0,2);
  new Object(this,glm::translate(mat4(1.0f),blv),bl,"Moon");
  blv += vec3(0,2,0);
  new Object(this,glm::translate(mat4(1.0f),blv),bl,"Moon");
  
  walkingstick->m_pos = vec3(10.0f,0.0f,2.0f);
  torch->m_pos = vec3(110.0,0.0,35.0);
  sword->m_pos = vec3(60.0,0.0,100.0);
  textbook->m_pos = vec3(10.0,0.0,50.0);
  
  m_player->m_pos = vec3(30.0,0.0,80.0);
  m_segway->m_pos = vec3(120.0,0.0,5.0);
  

  
  m_messenger = new Object(this,mat4(1.0f),0,"Don't Shoot Me");
  
  Model * thwomp = new Model("resources/models/blueblock.obj");
  Enemy * ethwomp = new Enemy(m_messenger, thwomp, THWOMP);
  ethwomp->m_pos = vec3(40.0f,m_terrain->getHeight(40,50)+8.0f,50.0f);
  ethwomp->m_rot = 270.0f;
  
  Model * fish = new Model("resources/models/fish.obj");
  Enemy * efish = new Enemy(m_messenger, fish, FISH);
  efish->m_pos = vec3(20.0f,-2.0f,100.0f);
  
  Model * fairy = new Model("resources/models/fairy.obj");
  m_navi = new Enemy(m_messenger, fairy, NAVI);
  m_navi->m_pos = vec3(30.0f,5.0f,80.0f);
  
  m_water = new Water(this);
  
  //mat4 fireModel = glm::translate(mat4(1.0f), vec3(115.0f, 0.0f,5.0f));
  //m_fire = new Fire(this, fireModel);
}

